/**
 * ImageHelper
 */

  import "babel-polyfill";

  class ImageHelper {
      constructor () {
          this.CONSTS = {
              IMAGE_TAGNAME: "IMG",
              NO_PICTURE_SRC: "/static/new_version/image/default_picture.jpg"
          };
      }
      setResource (node, src) {
          // image
          if (node.tagName === this.CONSTS.IMAGE_TAGNAME){
              node.src = src;
          // div, span
          } else {
              node.style.background = "url(" + src + ") no-repeat center";
          }
      }
      preloadImage (node, src) {
          let tempImage = new Image();
          return () => {
              tempImage.onload = () => {
                  this.setResource(node, tempImage.src);
                  node = null;
                  tempImage = null;
              }
              tempImage.src = src;
          }
      }
      preload (node, src) {
        　if (node){
              this.preloadImage(node, src)();
              this.setResource(node, this.CONSTS.NO_PICTURE_SRC);
          }
      }
  }

  export default new ImageHelper();
